<?php

namespace app\common\model;

use think\Model;

class Article extends Model
{
    protected $pk='art_id';
    protected $table='st_article';
    public function saveArt($data){

        if(!empty($data['art_id'])){
            $res=$this->allowField(true)->save($data,['art_id'=>$data['art_id']]);
            if($res){
                return ['valid'=>1,'msg'=>'编辑成功'];
            }else{
                return ['valid'=>0,'msg'=>'编辑失败'];
            }
        }
        $checkName=$this->where('art_name',$data['art_name'])->find();
        if($checkName){
            return ['valid'=>0,'msg'=>'文件名称已存在'];
        }else{
            $data['art_creat_time']=time();
            $res=$this->allowField(true)->save($data);
            if($res){
                return ['valid'=>1,'msg'=>'添加成功'];
            }else{
                return ['valid'=>0,'msg'=>'添加失败'];
            }
        }
    }
}
